package exam.service.impl;

import exam.bean.PermissionsRelation;
import exam.dao.PermissionRelationDao;
import exam.service.IPermissionRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissionRelationServiceImpl implements IPermissionRelationService {

    @Autowired
    PermissionRelationDao relationDao;

    @Override
    public int deleteInfo(Integer permissionGroupId) {
        return relationDao.deletePermission(permissionGroupId);
    }

    @Override
    public int insertInfoOfList(List<Integer> permissionsRelations,Integer permissionGroupId) {
        int countRe = 0;
        System.out.println(permissionsRelations.size());

        for (Integer item:permissionsRelations) {
            PermissionsRelation relation = new PermissionsRelation();
            relation.setPermissionGroupId(permissionGroupId);
            relation.setPermissionsId(item);
            countRe += relationDao.insertPermission(relation);
        }
        return countRe;
    }

    @Override
    public List<Integer> getPerIdOfByGroupId(Integer groupId) {
        return relationDao.getPerIdOfByGroupId(groupId);
    }
}
